load("//tools:defaults.bzl", "jasmine_node_test", "pkg_npm", "ts_library")

filegroup(
    name = "builders_assets",
    srcs = glob([
        "**/schema.json",
    ] + [
        "package.json",
        "README.md",
        "builders.json",
    ]),
)

ts_library(
    name = "builders",
    srcs = glob(
        ["**/*.ts"],
        exclude = [
            "testing/**",
            "**/*.spec.ts",
        ],
    ),
    module_name = "@nguniversal/builders",
    tsconfig = ":bazel-tsconfig-build.json",
    deps = [
        "//modules/common/clover/server",
        "//modules/common/engine",
        "//modules/common/tools",
        "@npm//@angular-devkit/architect",
        "@npm//@angular-devkit/build-angular",
        "@npm//@angular-devkit/core",
        "@npm//@angular/core",
        "@npm//@angular/platform-server",
        "@npm//@types/browser-sync",
        "@npm//@types/express",
        "@npm//guess-parser",
        "@npm//http-proxy-middleware",
        "@npm//ora",
        "@npm//piscina",
        "@npm//rxjs",
        "@npm//tree-kill",
    ],
)

pkg_npm(
    name = "npm_package",
    package_name = "@nguniversal/builders",
    srcs = [":builders_assets"],
    tags = ["release"],
    visibility = [
        "//integration:__subpackages__",
    ],
    deps = [":builders"],
)

## Testing rules
ts_library(
    name = "unit_test_lib",
    testonly = True,
    srcs = glob(
        [
            "testing/*.ts",
            "**/*.spec.ts",
        ],
        exclude = ["testing/hello-world-app/**/*"],
    ),
    deps = [
        ":builders",
        "@npm//@angular-devkit/architect",
        "@npm//@angular-devkit/build-angular",
        "@npm//@angular-devkit/core",
        "@npm//@angular/cli",
        "@npm//@angular/common",
        "@npm//@angular/compiler",
        "@npm//@angular/compiler-cli",
        "@npm//@angular/platform-browser",
        "@npm//@angular/platform-browser-dynamic",
        "@npm//@angular/router",
        "@npm//@types/browser-sync",
        "@npm//browser-sync",
        "@npm//express",
        "@npm//guess-parser",
        "@npm//node-fetch",
        "@npm//rxjs",
    ],
)

jasmine_node_test(
    name = "unit_test",
    srcs = [":unit_test_lib"],
    data = glob([
        "testing/hello-world-app/**/*",
    ]),
    deps = [
        ":common_npm_package_workaround",
        ":npm_package",
    ],
)

# Workaround for https://github.com/angular/angular/blob/e1c2fbd2aff5c4dce29d1153cea4ce117b7d83f5/packages/bazel/src/ng_package/ng_package.bzl#L542-L549
pkg_npm(
    name = "common_npm_package_workaround",
    package_name = "@nguniversal/common",
    srcs = ["//modules/common:npm_package"],
)
